#include "pageothertests.h"
#include "ui_pageothertests.h"

PageOtherTests::PageOtherTests(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageOtherTests)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);
}

PageOtherTests::~PageOtherTests()
{
    delete ui;
}

void PageOtherTests::on_Btn_Return_clicked()
{
    emit returnToMaintMenu();
}

void PageOtherTests::on_Button_AuxCompressor_Start_clicked()
{
    emit signal_AuxCompStart(true);
    ui->Button_AuxCompressor_Start->setEnabled(false);
    QTimer::singleShot(5000,this,[=](){
        emit signal_AuxCompStart(false);
        ui->Button_AuxCompressor_Start->setEnabled(true);
    });
}

void PageOtherTests::on_Button_NSK_clicked(bool checked)
{
    emit signal_NSKCutOff(checked);
}

void PageOtherTests::on_Button_SwitchToNet_clicked(bool checked)
{
    emit signal_SwitchToNet(checked);
    ui->Button_SwitchToNet->setText(checked?"转换至硬线":"转换至网络");
}

void PageOtherTests::on_Button_WheelTreadClean_clicked()
{
    emit signal_WheelTreadClean(true);
    ui->Button_WheelTreadClean->setEnabled(false);
    QTimer::singleShot(5000,this,[=](){
        emit signal_WheelTreadClean(false);
        ui->Button_WheelTreadClean->setEnabled(true);
    });
}

void PageOtherTests::on_Button_EDBCut_2_clicked(bool checked)
{
    emit signal_EDBCut(0,checked);
}

void PageOtherTests::on_Button_EDBCut_3_clicked(bool checked)
{
    emit signal_EDBCut(1,checked);
}

void PageOtherTests::on_Button_EDBCut_4_clicked(bool checked)
{
    emit signal_EDBCut(2,checked);
}

void PageOtherTests::on_Button_EDBCut_5_clicked(bool checked)
{
    emit signal_EDBCut(3,checked);
}

void PageOtherTests::setHSCBStat(uint8_t index, uint8_t stat)
{
    if(index == 0)
        setHSCBLabelStat(ui->HSCB_2,stat);
    else if(index == 1)
        setHSCBLabelStat(ui->HSCB_3,stat);
    else if(index == 2)
        setHSCBLabelStat(ui->HSCB_4,stat);
    else if(index == 3)
        setHSCBLabelStat(ui->HSCB_5,stat);
}

void PageOtherTests::setHSCBLabelStat(QLabel *hscb_label,uint8_t stat)
{
    switch (stat) {
    case 0:
        hscb_label->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    case 4:
        hscb_label->setStyleSheet("border-image: url(:/Images/HSCB_close.png);");
        break;
    case 3:
        hscb_label->setStyleSheet("border-image: url(:/Images/HSCB_open.png);");
        break;
    case 1:
        hscb_label->setStyleSheet("border-image: url(:/Images/HSCB_openflt.png);");
        break;
    case 2:
        hscb_label->setStyleSheet("border-image: url(:/Images/HSCB_closeflt.png);");
        break;
    default:
        hscb_label->setStyleSheet("border-image: url(:/Images/Unknow.png);");
        break;
    }
}

void PageOtherTests::on_Button_HSCB_Close_clicked()
{
    emit signal_HSCB_Close(true);
    ui->Button_HSCB_Close->setEnabled(false);
    ui->Button_HSCB_Open->setEnabled(false);
    QTimer::singleShot(3000,this,[=](){
        emit signal_HSCB_Close(false);
        ui->Button_HSCB_Close->setEnabled(true);
        ui->Button_HSCB_Open->setEnabled(true);
    });
}

void PageOtherTests::on_Button_HSCB_Open_clicked()
{
    emit signal_HSCB_Open(true);
    ui->Button_HSCB_Close->setEnabled(false);
    ui->Button_HSCB_Open->setEnabled(false);
    QTimer::singleShot(3000,this,[=](){
        emit signal_HSCB_Open(false);
        ui->Button_HSCB_Close->setEnabled(true);
        ui->Button_HSCB_Open->setEnabled(true);
    });
}
